var katalonLocatorsPriorityStorage = "katalonLocatorsPriorityStorage";
var isKatalonLocatorsSort = "isKatalonLocatorsSort";

function setKatalonLocatorsPriority(locatorPriority) {
    chrome.storage.local.set({ katalonLocatorsPriorityStorage: locatorPriority },
        function() {
            if (chrome.runtime.error) {
                console.log("Runtime error setting katalonLocatorsPriorityStorage to storage.");
                return;
            }
            //console.log("Katalon server locatorPriority set to " + locatorPriority);      
        });
}

function getKatalonLocatorsPriority(callback) {
    var locatorPriority = "";
    chrome.storage.local.get(katalonLocatorsPriorityStorage, function(result) {

        if (!(katalonLocatorsPriorityStorage in result)) {
            locatorPriority = "ui,id,link,name,dom:name,xpath:link,xpath:img,xpath:attributes,xpath:idRelative,xpath:href,dom:index,xpath:position,css,xpath:neighbor,xpath:class:text,xpath:label:text,xpath:class";
            //setKatalonLocatorsPriority(locatorPriority);
        } else {
            locatorPriority = result[katalonLocatorsPriorityStorage];
        }
        callback(locatorPriority);
    })
}

function setIsKatalonLocatorsSort(isSort) {
    chrome.storage.local.set({ isKatalonLocatorsSort: isSort },
        function() {
            if (chrome.runtime.error) {
                console.log("Runtime error setting isKatalonLocatorsSort to storage.");
                return;
            }
            //console.log("Katalon server isKatalonLocatorsSort set to " + isKatalonLocatorsSort);
        });
}

function getIsKatalonLocatorsSort(callback) {
    var tmp = null;
    chrome.storage.local.get(isKatalonLocatorsSort, function(result) {

        if (!(isKatalonLocatorsSort in result)) {
            tmp = false;
        } else {
            if (result[isKatalonLocatorsSort] == "false") {
                tmp = false;
            } else {
                tmp = true;
            }
        }
        callback(tmp);
    })
}